const Router = require('koa-router')
const { getConf } = require('../config/config')
const path = require('path')
const fs = require('fs')

const route = new Router({
  prefix: getConf('api:prefix') || '/api'
})

const files = fs.readdirSync(__dirname)
for (let i = 0; i < files.length; i++) {
  const filename = path.join(__dirname, files[i])
  if (filename !== __filename) {
    const r = require(filename)
    route.use(r.routes()).use(r.allowedMethods())
  }
}

module.exports = route
